package com.jet.member.remote.cashier;

import com.jet.core.exception.CustomException;
import com.jet.core.result.ResultJson;
import com.jet.member.remote.cashier.vo.MemberCashierLastOrderVo;
import com.jet.member.remote.cashier.vo.MemberCashierSummaryVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author dcl
 * @since 2025/2/21 15:07
 */
@Service
@Slf4j
public class MemberCashierRemote {

    private final MemberCashierRemoteFeign memberCashierRemoteFeign;

    public MemberCashierRemote(MemberCashierRemoteFeign memberCashierRemoteFeign) {
        this.memberCashierRemoteFeign = memberCashierRemoteFeign;
    }

    public MemberCashierLastOrderVo getMemberCashierLastOrder(long merchantNo, String memberId) {
        ResultJson<MemberCashierLastOrderVo> result = memberCashierRemoteFeign.getMemberCashierLastOrder(merchantNo, memberId);
        if (result.getCode() != ResultJson.ok().getCode()) {
            log.error("获取会员会后消费信息异常，{}", result.getMsg());
            throw new CustomException(result.getMsg());
        }
        return result.getData();
    }

    public MemberCashierSummaryVo getMemberCashierSummary(long merchantNo, String memberId) {
        ResultJson<MemberCashierSummaryVo> result = memberCashierRemoteFeign.getMemberCashierSummary(merchantNo, memberId);
        if (result.getCode() != ResultJson.ok().getCode()) {
            log.error("获取会员消费统计信息异常，{}", result.getMsg());
            throw new CustomException(result.getMsg());
        }
        return result.getData();
    }
}
